package com.yima.baseproj.module.sys.picture;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.yima.baseproj.aop.log.Logging;
import com.yima.baseproj.module.config.utils.PageUtil;
import com.yima.baseproj.module.config.utils.PageVo;
import com.yima.baseproj.module.sys.bill.BillEntity;
import com.yima.baseproj.module.sys.picture.model.PictureAddModel;
import com.yima.baseproj.module.sys.student.StudentEntity;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

@Api(tags = "相册管理")
@RequestMapping("/api/sys/picture")
@RestController
public class PictureController {

    @Autowired
    private PictureService pictureService;


//    @GetMapping("/findAllByPage")
//    public Object findAllByPage(PageVo page, PictureEntity picture) {
//        Page<Map> pageData = pictureService.findAllByPage(PageUtil.initMpPage(page),picture);
//        return pageData;
//    }

    @Logging(tags = "相册管理",value = "添加")
    @PreAuthorize("hasAuthority('sys:picture:add')")
    @ApiOperation("添加")
    @PostMapping("/add")
    public void save(@RequestBody @Validated PictureAddModel picture) {
        pictureService.add(picture,0);
    }

    @Logging(tags = "相册管理",value = "查询个人照片信息")
    @PreAuthorize("hasAuthority('sys:picture:findAllByPage')")
    @ApiOperation("根据学生id查询照片列表")
    @GetMapping("/findByStudentId/{studentId}")
    public List<PictureEntity> findByStudentId(@PathVariable int studentId){
        return pictureService.findByStudentId(studentId);
    }

    @Logging(tags = "相册管理",value = "修改")
    @PreAuthorize("hasAuthority('sys:picture:edit')")
    @ApiOperation("修改")
    @PostMapping("/edit")
    public void editKg(@RequestBody @Validated PictureEntity picture) {
        pictureService.edit(picture);
    }

    @Logging(tags = "相册管理",value = "删除")
    @PreAuthorize("hasAuthority('sys:picture:delByIds')")
    @ApiOperation("删除")
    @DeleteMapping(value = "/delByIds/{ids}")
    public void delByIds(@PathVariable int[] ids) {
        pictureService.delByIds(ids);
    }

    @ApiOperation("根据订单id查看已选照片")
    @GetMapping(value = "/findChoosePictureList/{billId}")
    public List<PictureEntity> findChoosePictureList(@PathVariable int billId) {
        return pictureService.findChoosePictureList(billId);
    }
}
